<template>
	<div>
		<div class="container">
			<div class="header">
				分类
			</div>
			<div class="content">
				<div class="left">
					<ul>
						<li v-for="item in listMain" :key="item.id"><span
							@click="activeId=item.id"
							:class="{active:item.id===activeId}">
							{{item.name}}</span></li>
					</ul>
				</div>
				<div class="right">
					<div>
						<img :src="avatar" alt="">
					</div>
					<ul v-if="listSub.length>0" class="list-sub">
						<li v-for="item in listSub" :key="item.id">
							<router-link :to="'/list/'+item.id">
								<div class="img">
									<img :src='item.avatar' alt="">
								</div>
								<p>{{ item.name }}</p>
							</router-link>
						</li>
					</ul>
				</div>
			</div>
			<div class="footer">
				<MiNav></MiNav>
			</div>
		</div>
	</div>
</template>

<script>
        import MiNav from '../../components/MiNav/MiNav.vue'
	import {CategoryApi} from '../../api';

        export default {
                components: {MiNav},
                name: "Category",
                data(){
                        return {
                                listMain: [],
                                listSub: [],
                                activeId: 0
                        }
                },

                computed: {
                        avatar: function(){
                                console.log(this.listMain.find(item => item.id === this.activeId))
                                return this.activeId > 0?this.listMain.find(item => item.id === this.activeId).avatar:"  ";

                        }
                },
                methods: {
	                async getData(fid){
                                try{
                                        const result=await CategoryApi.getList(fid);
                                        if(this.activeId === 0){
                                                this.listMain = result;
                                                this.activeId = result[0].id;
                                        }
                                        else{
                                                this.listSub = result;
                                        }
                                }catch(e){/**/}

	                }
                },
                watch: {
                        activeId: {
                                handler: function(newValue){
                                        this.getData(newValue)
                                },
                                immediate: true,
                        }
                }
        }
</script>
<style scoped>
	* {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.container {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.header {
		height: 13.5vw;
		background-color: white;
		flex-shrink: 0;
		line-height: 13.5vw;
		text-align: center;
		margin-bottom: 5px;
	}

	.content {
		flex-grow: 1;
		display: flex;
		overflow: hidden;
		background-color: rgb(246, 246, 246);
	}

	.left {
		width: 100px;
		background-color: white;
		flex-shrink: 0;
		overflow: auto;
	}

	.left > ul {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.left > ul > li {
		padding: 18px 0;
	}

	.left > ul > li > span {
		display: inline-block;
		width: 77px;
		text-align: center;
	}

	.right {
		width: 100%;
		flex-grow: 1;
		overflow: auto;
		display: flex;

		flex-direction: column;
		padding: 0 10px;
	}

	.banner {
		height: 76px;
		display: flex;
		flex-shrink: 0;
		margin-top: 11px;
	}

	.right > div {
		width: 100%;
	}

	.right > div > img {
		width: 100%;
		height: 100%;
	}


	.list-sub {
		display: flex;
		flex-wrap: wrap;
	}
	.list-sub li {
		width: 33.333333%;
		display: flex;
	}
	.list-sub a {
		width: 100%;
		text-decoration: none;
		color: rgb(119, 119, 119);
		text-align: center;
		font-size: 12px;
	}
	.list-sub img {
		width: 80%;
	}
	.img > img {
		width: 80%;
	}

	/*页脚部分*/
	.footer {
		height: 14.5vw;
		flex-shrink: 0;
		background-color: white;
	}
	.footer li:nth-child(2) i{
		background-position: 0px -72px !important;

	}

	.active {
		color: white;
		background-color: rgb(230, 170, 92);
		border-radius: 12px;
	}
</style>